package manager;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import org.junit.Test;

/**
 * 工具类
 * @author 凯
 *
 */
public class Utils {

	/**
	 * 获取当前时间
	 * @return
	 */
	public static String currentTime()
	{
		Date nowTime = new Date();
		SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		return time.format(nowTime);
	}
	
	/**
	 * 时间戳转格式化
	 * @param l
	 * @return
	 */
	public static String timestamp2Format(long l)
	{
		SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		return time.format(l);
	}
	
	public static String timestamp2Format2(long l)
	{
		SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); 
		return time.format(l);
	}
	
	// 獲取時間
	public static Calendar getCalendarByStr(String str)
	{
		
		SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		Date date = null;
		try {
			date = sdf.parse(str);
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar;
	}
	
	// 获取今天的时间,str格式：yyyy-MM-dd
	public static boolean isToday(String str_calendar)
	{
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String today = simpleDateFormat.format(Calendar.getInstance().getTime());
		return str_calendar.equals(today);
	}
	
	// 比较时间
	public static int compareTime(String str_calendar)
	{
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String today = simpleDateFormat.format(Calendar.getInstance().getTime());
		return str_calendar.compareTo(today);
	}
	
	// 从时间戳获取时间
	public static Calendar fromL(long l)
	{
		Date d = new Date(l);
		Calendar c = Calendar.getInstance();
		c.setTime(d);
		return c;
	}
	
}
